package com.hutou.chuangke.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hutou.chuangke.Bean.CollBean;
import com.hutou.chuangke.R;
import com.hutou.chuangke.activity.TrackDetailActivity;
import com.hutou.chuangke.activity.VideoViewActivity;
import com.hutou.chuangke.adapter.inteface.CommentOnclicListener;
import com.hutou.chuangke.widget.CircleImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/5/12.
 * 评论adapter
 */

public class CommentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private ArrayList<CollBean> mData = new ArrayList<>();
    private CommentOnclicListener mOnItemClickListener;
    public CommentAdapter(Context context){
        this.mContext = context;
    }

    public void setonItemListener(CommentOnclicListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new CommentAdapter.ListItemViewHolder(LayoutInflater.from(mContext)
                .inflate(R.layout.item_comment, null));
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof CommentAdapter.ListItemViewHolder) {
            CollBean bean = mData.get(position);
            ((CommentAdapter.ListItemViewHolder)holder).nametv.setText(bean.getSinger());
            ((CommentAdapter.ListItemViewHolder)holder).datetv.setText(bean.getCrttm());
            if(bean.getUpCollect()!=null) {
                ((CommentAdapter.ListItemViewHolder) holder).commenttv.setText("回复 "+bean.getUpCollect().getUpsinger()+":"+bean.getNote());
                ((CommentAdapter.ListItemViewHolder) holder).reply_commenttv.setVisibility(View.VISIBLE);
                ((CommentAdapter.ListItemViewHolder) holder).reply_commenttv.setText(bean.getUpCollect().getUpsinger()+":"
                        +bean.getUpCollect().getUpnote());
            }else{
                ((CommentAdapter.ListItemViewHolder) holder).commenttv.setText(bean.getNote());
                ((CommentAdapter.ListItemViewHolder) holder).reply_commenttv.setVisibility(View.GONE);
            }
            ImageLoader.getInstance().displayImage(bean.getUserimgurl(), ((CommentAdapter.ListItemViewHolder)holder).headiv);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int pos = holder.getLayoutPosition();
                mOnItemClickListener.onItemClick(view,pos);
            }
        });
    }

    public void setData(ArrayList<CollBean> mData) {
        this.mData = mData;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class ListItemViewHolder extends RecyclerView.ViewHolder {
        TextView nametv, datetv, praise_num_tv, commenttv, reply_commenttv;
        ImageView headiv, praiseiv;

        public ListItemViewHolder(View view) {
            super(view);
            nametv = (TextView) view.findViewById(R.id.nametv);
            datetv = (TextView) view.findViewById(R.id.datetv);
            praise_num_tv = (TextView) view.findViewById(R.id.praise_num_tv);
            commenttv = (TextView) view.findViewById(R.id.commenttv);
            reply_commenttv = (TextView) view.findViewById(R.id.reply_commenttv);
            headiv = (CircleImageView) view.findViewById(R.id.headiv);
            praiseiv = (ImageView) view.findViewById(R.id.praiseiv);
        }
    }

}
